//
//  HMProgressImageView.m
//  kuangjia
//
//  Created by 张帅 on 15/10/15.
//  Copyright © 2015年 ZhangShuai. All rights reserved.
//

#import "HMProgressImageView.h"

@interface HMProgressImageView ()


@end

@implementation HMProgressImageView

-(void)setProgress:(CGFloat)progress{

    _progress = progress;

    self.progressView.progress = progress;

    
}

-(HMProgressView *)progressView{

    if (_progressView==nil) {
        _progressView=[[HMProgressView alloc] initWithFrame:self.bounds];
    
        [self addSubview:_progressView];
        
        _progressView.frame= self.bounds;
        [_progressView setBackgroundColor:[UIColor clearColor]];
        
        
    
    }
    return _progressView;
}


@end


@implementation HMProgressView

-(void)setProgress:(CGFloat)progress{
    _progress=progress;
    
    [self  setNeedsDisplay];

}

-(void)drawRect:(CGRect)rect{

    if (_progress>=1) {
        return;
    
    }
    
    CGPoint center = CGPointMake(rect.size.width*0.5, rect.size.height*0.5);
    
    CGFloat r= MIN(rect.size.width, rect.size.height)*0.5;
    
    
    CGFloat start = M_PI;
    
    CGFloat end = self.progress*M_PI*2 +start;
    
    UIBezierPath *path =[UIBezierPath bezierPathWithArcCenter:center radius:r startAngle:start endAngle:end clockwise:YES];
    
    // 增加指向圆心的路径
    [path addLineToPoint:center];
    
     // 设置属性 - 在实际应用中，动画只是点缀，不要抢
    [[UIColor colorWithWhite:0 alpha:0.5] setFill];

    
    [path closePath];
    [path fill];

    
    
    NSLog(@"%@  %lf",NSStringFromCGRect(rect),self.progress);
}

@end